﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Windows;

namespace ReactiveCode.Observables
{
    [TestClass]
    public class ChangeListeningTests
    {
        class DepObj : DependencyObject
        {
            public object Value
            {
                get { return (object)GetValue(ValueProperty); }
                set { SetValue(ValueProperty, value); }
            }

            public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(object), typeof(DepObj), null);
        }

        [TestMethod]
        public void DependencyPropertyChangeNotificationsAreNotAsync()
        {
            DepObj obj = new DepObj();

            bool handledChange = false;

            ChangeListening.Observe(() => obj.Value)
                .Subscribe(delegate { handledChange = true; });

            obj.Value = 0;
            Assert.IsTrue(handledChange);
        }
    }
}
